import{it as e,wt as t}from"./B603vO-13smUKN.js";import{o as n}from"./aWDZHnvL3RQbKF.js";import{n as r}from"./BlinbWL5Vpb4O.js";import{On as i,b as a,fn as o,g as s,gn as c,it as l,k as u,mt as d,o as f,v as p,y as m}from"./CIxmKYxc4tZcJF.js";import{t as h}from"./BqxXgTEHXQHsE.js";import{O as g,_,g as v}from"./DcwiUW8R1GKRvl.js";import{i as y,n as b,r as x}from"./CRXWXnv73Tdqyd.js";import{c as S,o as C}from"./BbxvatETxeTHf.js";import{t as w}from"./B0soNaiAkILqi.js";import"./C3Xax3Tz4BagVD.js";import{c as T,m as E,r as D,t as O}from"./mI_k9xko4swc5U.js";import{t as k}from"./BM6O3YOS1QRtOq.js";function A(e){return e.map(e=>{let t=e,n=``;return n=t.type===`amount`?`${y(t.value)}`:t.type===`day`?`${b(t.value)}`:t.type===`iban`?`IBAN: ${t.value}`:t.type===`vatid`?`VATID: ${t.value}`:t.type===`phone`?`PHONE: ${t.value}`:t.type===`currency`?`${t.value} / ${t.string}`:t.type===`url`?`URL: ${r(t.value)} ${t.value}`:t.type===`email`?`EMAIL: ${t.value}`:t.type===`identifier`?`Identifier: ${t.value}`:t.type,{...t,tooltip:n}}).filter(t)}function j(e){return async(t,r)=>{let i=await v(t,r,e),a=new n(i).getInfo();return{foundPage:i,overlays:A(a),found:a}}}var M=u({__name:`app-pdf-view-doc`,props:{doc:{}},emits:[`overlays`],setup(t,{emit:n}){let r=t,u=n,{currency:v,taxRates:y}=w(),b=S(),A=c({pdf:void 0,html:``,asset:void 0}),M=new Set([`image/png`,`image/jpeg`,`image/webp`,`image/gif`,`image/avif`]);async function N(t){let n=t.bin;if(A.pdf?.loadingTask.destroy(),A.pdf=void 0,A.asset=void 0,A.html=``,n&&n.length>0)if(A.asset=t,t.type===`application/pdf`){let e=await O(n);A.pdf=e?o(e):void 0}else if(M.has(t.type)){let e=await O(await _(n,t.type));A.pdf=e?o(e):void 0}else t.type.startsWith(`text/`)&&(A.html=e(t.bin))}l(()=>A.pdf?.loadingTask.destroy());let P=s(()=>r.doc?.asset),F=s(()=>j(E(P.value)?.cid));T(P,N);function I(e){let t=e.event,n=e.item;function i(e){C.workspace?.updateItem(r.doc._id,{gross:e})}if(n.type===`amount`){let e=+n.value,r=x(e,v.value);h(()=>[{title:r,action:()=>i(e),disabled:!0},{},{title:`Set gross ${r}`,action:()=>i(e)},{title:`Set net ${r}`,action:()=>i(e)},{},...y.value.map(t=>({title:`Set tax at  ${t}`,action:()=>i(e)})),{},...y.value.map(t=>({title:`Set net at  ${t}`,action:()=>i(e)})),{},...y.value.map(t=>({title:`Set gross at  ${t}`,action:()=>i(e)}))])(t)}else n.type===`day`||n.type}return(e,n)=>P.value&&A.asset?(d(),a(f,{key:0},[A.pdf?(d(),p(i(D),{key:0,xxxthumbnail:i(k).thumbnails[t.doc?.asset??``],pdf:A.pdf,"show-text":!0,"show-overlays":!0,"overlay-update":F.value,"debug-text-layer":i(b)?.lDebugTextLayer,onOverlays:n[0]||=e=>u(`overlays`,e),onOverlayClick:I},null,8,[`xxxthumbnail`,`pdf`,`overlay-update`,`debug-text-layer`])):A.asset.type===`text/html`?(d(),p(g,{key:1,value:A.html,static:!1},null,8,[`value`])):m(``,!0)],64)):m(``,!0)}});export{M as default};